/*
 * @Author: szx
 * @Date: 2022-03-01 13:00:39
 * @LastEditTime: 2022-03-01 13:50:57
 * @Description:
 * @FilePath: \leetcode\1-99\6\6.js
 */
/**
 * @param {string} s
 * @param {number} numRows
 * @return {string}
 */
var convert = function (s, numRows) {
    const len = s.length;
    if (numRows == 1 || numRows >= len) return s;
    const t = numRows * 2 - 2;
    const res = [];
    // 每行开始
    for (let i = 0; i < numRows; i++) {
        // 每行的起始下标
        for (j = i; j < len; j += t) {
            res.push(s[j]);
            if (0 < i && i < numRows - 1) res.push(s[j + t - 2 * i]);
        }
    }
    return res.join('');
};
console.log(convert('PAYPALISHIRING', 3));
console.log(convert('PAYPALISHIRING', 4));
